package easy;

import java.util.Arrays;

public class Solution_1710 {
    public int maximumUnits(int[][] boxTypes, int truckSize) {
        Arrays.sort(boxTypes, (a, b) -> Integer.compare(b[1], a[1]));
        int sum = 0;
        for (int[] boxType : boxTypes) {
            int count = Math.min(truckSize, boxType[0]);
            sum += (count * boxType[1]);
            truckSize -= boxType[0];
            if (truckSize <= 0) {
                break;
            }

        }
        return sum;
    }

    public static void main(String[] args) {
        Solution_1710 model = new Solution_1710();
//        System.out.println(model.maximumUnits(new int[][]{{1, 3}, {2, 2}, {3, 1}}, 4));
        System.out.println(model.maximumUnits(new int[][]{{5, 10}, {2, 5}, {4, 7}, {3, 9}}, 10));
    }
}
